package com.v2future.sjt.collegecheckingattendance;

import android.app.Fragment;

/**
 * Created by Administrator on 2016/1/14.
 */
public abstract class LazyFragment extends BaseFragment{

    protected boolean isVisible;

    // 标志位，标志已经初始化完成。
    public boolean isPrepared = false;

    /**
     * 在这里实现Fragment数据的缓加载.
     * @param isVisibleToUser
     */
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }

    protected void onVisible(){
        if (!isPrepared)
        lazyLoad();
    }

    protected abstract void lazyLoad();

    protected void onInvisible(){}
}
